<%@page import="qldc.pm.qtht.dmdc.constants.MaLoaiHoSo"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@page import="qldc.pm.tienan.constants.ChucNangPhanMemPermision"%>
<%@page import="qldc.pm.qtht.utils.NguoiDungUtils"%>
<%@page import="qldc.pm.qtht.model.ChucNangPhanMem"%>
<%@page import="java.util.List"%>
<%@page import="com.liferay.portal.kernel.util.StringPool"%>
<%@page import="qldc.pm.tienan.constants.TienAnConstants"%>

<%@ include file="../init.jsp"%>

<%
PortletURL portletURL = renderResponse.createRenderURL();
portletURL.setParameter("mvcPath", "/html/view.jsp");

List<ChucNangPhanMem> tongChucNangPhanMems = NguoiDungUtils.getChucNangTheoNguoiDung(MaLoaiHoSo.QLTA.toString(), user.getUserId());
String chucNangItem = "";
Map<String, ChucNangPhanMem> chucNangPhanMems = new HashMap<String, ChucNangPhanMem>();

for (ChucNangPhanMem chucNangPhanMem : tongChucNangPhanMems) {
	if (Validator.isNotNull(chucNangPhanMem)) {
		chucNangPhanMems.put(chucNangPhanMem.getMaChucNangPhanMem(), chucNangPhanMem);
	}
}

if(!chucNangPhanMems.isEmpty()) {
	if (null != chucNangPhanMems.get(ChucNangPhanMemPermision.TIENAN_NCTS.getMaChucNang())) {
		chucNangItem = ChucNangPhanMemPermision.TIENAN_NCTS.getChucNang();
	}
	
	if(Validator.isNull(chucNangItem)) {
		chucNangItem = ChucNangPhanMemPermision.fromMaChucNang(tongChucNangPhanMems.get(0).getMaChucNangPhanMem()).getChucNang();
	}
}

String chonChucNangItem = ParamUtil.getString(request, "chonChucNangItem", chucNangItem);
%>

<div class="header">
	<liferay-ui:message key="chon-chuc-nang" />
</div>

<div class="navigation">
	<ul class="qtht-list">
		<%
		for (String maChucNang : chucNangPhanMems.keySet()) {

			try {
				chucNangItem = ChucNangPhanMemPermision.valueOf(chucNangPhanMems.get(maChucNang).getMaChucNangPhanMem()).getChucNang();
			} catch (Exception e) {
				chucNangItem = chucNangPhanMems.get(maChucNang).getMaChucNangPhanMem();
			}
			
			boolean isActive = chonChucNangItem.equalsIgnoreCase(chucNangItem);
			if (chonChucNangItem.equals("DanhSachBKTT") && chucNangItem.equalsIgnoreCase("BaoCaoThongKe")) {
				isActive = true;
			}
		%>
		
		<li <%=isActive ? "class='active'" : StringPool.BLANK %>>
		
			<%
			portletURL.setParameter("chonChucNangItem", chucNangItem);
			%>
			<a href="<%=portletURL.toString()%>"><%=chucNangPhanMems.get(maChucNang).getTenChucNangPhanMem()%></a>
		</li>

		<%
		}
		%>
	</ul>
</div>

